package cn.mesmile.admin.modules.system.controller;

import cn.mesmile.admin.common.result.R;
import cn.mesmile.admin.modules.system.service.ISignInService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.Map;

/**
 * @author zb
 * @Description 用户签到相关api
 */
@Validated
@Api(value = "用户签到相关api", tags = {"用户签到相关api"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/v1/sign-in")
public class SignInController {

    private final ISignInService signInService;

    @PostMapping("/sign")
    @ApiOperation("签到")
    @ApiImplicitParam(value = "查询时间", name = "localDate", defaultValue = "")
    public R signIn(@RequestParam(value = "localDate", required = false) LocalDate localDate) {
        // todo userId从token中取
        localDate = localDate == null ? LocalDate.now() : localDate;
        boolean b = signInService.signIn(123L, localDate);
        return R.status(b);
    }

    @PostMapping("/check-sign")
    @ApiOperation("检查签到")
    @ApiImplicitParam(value = "查询时间", name = "localDate", defaultValue = "")
    public R checkSignIn(@RequestParam(value = "localDate", required = false) LocalDate localDate) {
        // todo userId从token中取
        localDate = localDate == null ? LocalDate.now() : localDate;
        boolean b = signInService.checkSignIn(123L, localDate);
        return R.data(b);
    }

    @GetMapping("/getSignInCount")
    @ApiOperation("获取指定月份签到次数")
    @ApiImplicitParam(value = "获取指定月份签到次数", name = "localDate", defaultValue = "")
    public R getSignInCount(@RequestParam(value = "localDate", required = false) LocalDate localDate) {
        // todo userId从token中取
        localDate = localDate == null ? LocalDate.now() : localDate;
        int signInCount = signInService.getSignInCount(123L, localDate);
        return R.data(signInCount);
    }

    @GetMapping("/getSignInContinuityCount")
    @ApiOperation("获取指定月份连续签到次数")
    @ApiImplicitParam(value = "获取指定月份连续签到次数", name = "localDate", defaultValue = "")
    public R getSignInContinuityCount(@RequestParam(value = "localDate", required = false) LocalDate localDate) {
        // todo userId从token中取
        localDate = localDate == null ? LocalDate.now() : localDate;
        int signInContinuityCount = signInService.getSignInContinuityCount(123L, localDate);
        return R.data(signInContinuityCount);
    }

    @GetMapping("/getSignInInfo")
    @ApiOperation("获取指定月份首次签到日期")
    @ApiImplicitParam(value = "获取指定月份首次签到日期", name = "localDate", defaultValue = "")
    public R getFirstSignInByDate(@RequestParam(value = "localDate", required = false) LocalDate localDate) {
        // todo userId从token中取
        localDate = localDate == null ? LocalDate.now() : localDate;
        LocalDate firstSignInByDate = signInService.getFirstSignInByDate(123L, localDate);
        return R.data(firstSignInByDate);
    }

    @PostMapping("/getSignInInfo")
    @ApiOperation("获取指定年月签到信息")
    @ApiImplicitParam(value = "获取指定年月签到信息", name = "localDate", defaultValue = "")
    public R getSignInInfo(@RequestParam(value = "localDate", required = false) LocalDate localDate) {
        // todo userId从token中取
        localDate = localDate == null ? LocalDate.now() : localDate;
        Map<LocalDate, Boolean> signInInfo = signInService.getSignInInfo(123L, localDate);
        return R.data(signInInfo);
    }


}
